package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import org.springframework.stereotype.Service;

@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {
    @Override
    public void addBankAccount(BankAccountUpsertReqDTO bankAccountUpsertReqDTO) {
        // 获取当前用户id
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = BeanUtil.toBean(bankAccountUpsertReqDTO, BankAccount.class);
        bankAccount.setId(userId);
        this.saveOrUpdate(bankAccount);
    }

    @Override
    public BankAccountResDTO getBankAccount() {
        // 获取当前用户id
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = this.getById(userId);
        if (bankAccount != null) {
            return BeanUtil.toBean(bankAccount, BankAccountResDTO.class);
        }
        return null;
    }
}
